/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('viapi-oxs-cross', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model LingJieApiInvokeCount {
  apiName?: string(name='ApiName'),
  metrics?: [ 
    {
      count?: int32(name='Count'),
      day?: string(name='Day'),
      hour?: string(name='Hour'),
    }
  ](name='Metrics'),
  projectId?: string(name='ProjectId'),
  region?: string(name='Region'),
  statisticsUnit?: string(name='StatisticsUnit'),
  timeUnit?: string(name='TimeUnit'),
}

model LingJieApiInvokeQps {
  apiName?: string(name='ApiName'),
  metrics?: [ 
    {
      day?: string(name='Day'),
      hour?: string(name='Hour'),
      maxQps?: int32(name='MaxQps'),
    }
  ](name='Metrics'),
  projectId?: string(name='ProjectId'),
  region?: string(name='Region'),
  statisticsUnit?: string(name='StatisticsUnit'),
  timeUnit?: string(name='TimeUnit'),
}

model LingJieOpenStatus {
  commoditiesOpenStatus?: [ 
    {
      cnName?: string(name='CnName'),
      commodity?: string(name='Commodity'),
      describe?: string(name='Describe'),
      detailPage?: string(name='DetailPage'),
      open?: boolean(name='Open'),
      openTime?: string(name='OpenTime'),
    }
  ](name='CommoditiesOpenStatus'),
  openTime?: string(name='OpenTime'),
  productConsoleUrl?: string(name='ProductConsoleUrl'),
  productEnabled?: boolean(name='ProductEnabled'),
  productMonitorUrl?: string(name='ProductMonitorUrl'),
  productWikiUrl?: string(name='ProductWikiUrl'),
}

model LingJieOpenStatusDetail {
  apiList?: [ 
    {
      cnName?: string(name='CnName'),
      concurrentLimit?: string(name='ConcurrentLimit'),
      enName?: string(name='EnName'),
      moreOperations?: [ 
        {
          clickUrl?: string(name='ClickUrl'),
          operation?: string(name='Operation'),
        }
      ](name='MoreOperations'),
      statisticsUnit?: string(name='StatisticsUnit'),
      status?: string(name='Status'),
      usage?: string(name='Usage'),
    }
  ](name='ApiList'),
  commodityConcurrentLimitTips?: string(name='CommodityConcurrentLimitTips'),
  commodityHasOpen?: boolean(name='CommodityHasOpen'),
  commodityOpenUrl?: string(name='CommodityOpenUrl'),
  commodityUsageTips?: string(name='CommodityUsageTips'),
  userStopMode?: boolean(name='UserStopMode'),
}

model News {
  content?: string(name='Content'),
  gmtCreate?: string(name='GmtCreate'),
  gmtModified?: string(name='GmtModified'),
  id?: long(name='Id'),
  last?: boolean(name='Last'),
  pic?: string(name='Pic'),
  sort?: int32(name='Sort'),
  status?: int32(name='Status'),
  tags?: string(name='Tags'),
  title?: string(name='Title'),
  type?: int32(name='Type'),
  url?: string(name='Url'),
}

model UserQpsDetail {
  apiName?: string(name='ApiName'),
  day?: string(name='Day'),
  qps?: int32(name='Qps'),
  qpsRule?: string(name='QpsRule'),
  status?: int32(name='Status'),
}

model CreateSDKInstanceRequest {
  bundleId?: string(name='BundleId'),
  pk?: string(name='Pk'),
  platform?: string(name='Platform'),
  recipe?: string(name='Recipe'),
  validFrom?: long(name='ValidFrom'),
  validTo?: long(name='ValidTo'),
}

model CreateSDKInstanceResponseBody = {
  code?: string(name='Code'),
  data?: string(name='Data'),
  errorMessage?: string(name='ErrorMessage'),
  httpCode?: int32(name='HttpCode'),
  ok?: boolean(name='Ok'),
  requestId?: string(name='RequestId'),
}

model CreateSDKInstanceResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: CreateSDKInstanceResponseBody(name='body'),
}

async function createSDKInstanceWithOptions(request: CreateSDKInstanceRequest, runtime: Util.RuntimeOptions): CreateSDKInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.bundleId)) {
    query['BundleId'] = request.bundleId;
  }
  if (!Util.isUnset(request.pk)) {
    query['Pk'] = request.pk;
  }
  if (!Util.isUnset(request.platform)) {
    query['Platform'] = request.platform;
  }
  if (!Util.isUnset(request.recipe)) {
    query['Recipe'] = request.recipe;
  }
  if (!Util.isUnset(request.validFrom)) {
    query['ValidFrom'] = request.validFrom;
  }
  if (!Util.isUnset(request.validTo)) {
    query['ValidTo'] = request.validTo;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'CreateSDKInstance',
    version = '2020-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function createSDKInstance(request: CreateSDKInstanceRequest): CreateSDKInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return createSDKInstanceWithOptions(request, runtime);
}

model GetSDKInstanceDebugInfoRequest {
  instanceId?: string(name='InstanceId'),
}

model GetSDKInstanceDebugInfoResponseBody = {
  code?: string(name='Code'),
  data?: {
    bundleId?: string(name='BundleId'),
    createdAt?: string(name='CreatedAt'),
    events?: [ 
      {
        content?: string(name='Content'),
        id?: long(name='Id'),
        success?: boolean(name='Success'),
        timeStamp?: string(name='TimeStamp'),
      }
    ](name='Events'),
    instanceId?: string(name='InstanceId'),
    latestBuild?: string(name='LatestBuild'),
    platform?: string(name='Platform'),
    recipe?: string(name='Recipe'),
    status?: string(name='Status'),
    updatedAt?: string(name='UpdatedAt'),
    validFromDate?: string(name='ValidFromDate'),
    validToDate?: string(name='ValidToDate'),
  }(name='Data'),
  errorMessage?: string(name='ErrorMessage'),
  httpCode?: int32(name='HttpCode'),
  ok?: boolean(name='Ok'),
  requestId?: string(name='RequestId'),
}

model GetSDKInstanceDebugInfoResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: GetSDKInstanceDebugInfoResponseBody(name='body'),
}

async function getSDKInstanceDebugInfoWithOptions(request: GetSDKInstanceDebugInfoRequest, runtime: Util.RuntimeOptions): GetSDKInstanceDebugInfoResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.instanceId)) {
    query['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'GetSDKInstanceDebugInfo',
    version = '2020-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function getSDKInstanceDebugInfo(request: GetSDKInstanceDebugInfoRequest): GetSDKInstanceDebugInfoResponse {
  var runtime = new Util.RuntimeOptions{};
  return getSDKInstanceDebugInfoWithOptions(request, runtime);
}

model QuerySDKInstancesRequest {
  codeList?: string(name='CodeList'),
  createdAfterDate?: string(name='CreatedAfterDate'),
  createdBeforeDate?: string(name='CreatedBeforeDate'),
  pageNumber?: int32(name='PageNumber'),
  pageSize?: int32(name='PageSize'),
  pk?: string(name='Pk'),
}

model QuerySDKInstancesResponseBody = {
  code?: string(name='Code'),
  data?: {
    content?: [ 
      {
        bundleId?: string(name='BundleId'),
        createdAt?: string(name='CreatedAt'),
        instanceId?: string(name='InstanceId'),
        latestBuild?: string(name='LatestBuild'),
        platform?: string(name='Platform'),
        recipe?: string(name='Recipe'),
        status?: string(name='Status'),
        updatedAt?: string(name='UpdatedAt'),
        userId?: string(name='UserId'),
        validFromDate?: string(name='ValidFromDate'),
        validToDate?: string(name='ValidToDate'),
      }
    ](name='Content'),
    pageNumber?: int32(name='PageNumber'),
    pageSize?: int32(name='PageSize'),
    totalCount?: int32(name='TotalCount'),
  }(name='Data'),
  errorMessage?: string(name='ErrorMessage'),
  httpCode?: int32(name='HttpCode'),
  ok?: boolean(name='Ok'),
  requestId?: string(name='RequestId'),
}

model QuerySDKInstancesResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: QuerySDKInstancesResponseBody(name='body'),
}

async function querySDKInstancesWithOptions(request: QuerySDKInstancesRequest, runtime: Util.RuntimeOptions): QuerySDKInstancesResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.codeList)) {
    query['CodeList'] = request.codeList;
  }
  if (!Util.isUnset(request.createdAfterDate)) {
    query['CreatedAfterDate'] = request.createdAfterDate;
  }
  if (!Util.isUnset(request.createdBeforeDate)) {
    query['CreatedBeforeDate'] = request.createdBeforeDate;
  }
  if (!Util.isUnset(request.pageNumber)) {
    query['PageNumber'] = request.pageNumber;
  }
  if (!Util.isUnset(request.pageSize)) {
    query['PageSize'] = request.pageSize;
  }
  if (!Util.isUnset(request.pk)) {
    query['Pk'] = request.pk;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QuerySDKInstances',
    version = '2020-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function querySDKInstances(request: QuerySDKInstancesRequest): QuerySDKInstancesResponse {
  var runtime = new Util.RuntimeOptions{};
  return querySDKInstancesWithOptions(request, runtime);
}

model StartSDKInstanceProductionRequest {
  instanceId?: string(name='InstanceId'),
}

model StartSDKInstanceProductionResponseBody = {
  code?: string(name='Code'),
  errorMessage?: string(name='ErrorMessage'),
  httpCode?: int32(name='HttpCode'),
  ok?: boolean(name='Ok'),
  requestId?: string(name='RequestId'),
}

model StartSDKInstanceProductionResponse = {
  headers: map[string]string(name='headers'),
  statusCode: int32(name='statusCode'),
  body: StartSDKInstanceProductionResponseBody(name='body'),
}

async function startSDKInstanceProductionWithOptions(request: StartSDKInstanceProductionRequest, runtime: Util.RuntimeOptions): StartSDKInstanceProductionResponse {
  Util.validateModel(request);
  var body : map[string]any = {};
  if (!Util.isUnset(request.instanceId)) {
    body['InstanceId'] = request.instanceId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'StartSDKInstanceProduction',
    version = '2020-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

async function startSDKInstanceProduction(request: StartSDKInstanceProductionRequest): StartSDKInstanceProductionResponse {
  var runtime = new Util.RuntimeOptions{};
  return startSDKInstanceProductionWithOptions(request, runtime);
}

